<?xml version="1.0"?>

<f:view
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
>
	<h:head />
	<h:body>
		<h:form id="cars-form">  
			
			<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" globalOnly="true"/>
			
			<h:outputText value="Cars: " />
			<BR/>
			<p:dataTable id="results" value="#{carsBean.advertisings}" var="row" emptyMessage="No result"
					paginator="true" rows="10" paginatorPosition="bottom"
					paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}  {CurrentPageReport}"
					>
				
				<p:column headerText="Manufacturer" sortBy="#{carsBean.getManufacturerString(row)}">
					<h:outputText value="#{carsBean.getManufacturerString(row)}" />
				</p:column>
				<p:column headerText="Model" sortBy="#{carsBean.getModelString(row)}">
					<h:outputText value="#{carsBean.getModelString(row)}" />
				</p:column>
				<p:column headerText="Location" sortBy="#{row.location}">
					<h:outputText value="#{row.location}" />
				</p:column>
				<p:column headerText="Details">
					<h:outputText value="#{row.carDescription}" />
				</p:column>
				<p:column style="text-align:right;">  
					<p:commandButton icon="ui-icon-triangle-1-w" id="actions" value="Operations"  iconPos="left" />
					<p:tieredMenu overlay="true" trigger="actions" my="right top" at="left center" autoDisplay="true">
				       <p:menuitem value="Edit" update=":createCarForm" actionListener="#{createCarBean.init(row)}" 
				       			 ajax="true" icon="ui-icon-comment" onsuccess="createDlg.show()"/>
				       <p:menuitem value="Delete" oncomplete="deleteConfirmation.show()" update=":cars-form:deleteConfirmDialog" 
				       			ajax="true" icon="ui-icon-trash" >
				           <f:setPropertyActionListener target="#{carsBean.selectedAd}" value="#{row}" />
				       </p:menuitem>
					</p:tieredMenu>
		        </p:column>   
				
			</p:dataTable>
			
			<p:commandButton value="Create new" actionListener="#{createCarBean.init}" update=":createCarForm" onsuccess="createDlg.show()"/>
			
			<p:confirmDialog id="deleteConfirmDialog" message="Do you realy want to delete this?" header="Delete" severity="alert" 
			        widgetVar="deleteConfirmation" closeOnEscape="true" >
			
			    <p:commandButton id="deleteButton" value="yes" update=":cars-form" oncomplete="deleteConfirmation.hide()" actionListener="#{carsBean.delete()}" />
			    <p:commandButton id="deleteCancel" value="no" onclick="deleteConfirmation.hide()" type="button" />
			
			</p:confirmDialog>
			
		</h:form>
		
		<p:dialog id="createCarsDialog" widgetVar="createDlg" header="Create Advertising" modal="true" resizable="false">
			<ui:include src="create_car.xhtml" />
			
		</p:dialog>
	</h:body>
</f:view>